# -*- coding: utf-8 -*-..,
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2014 Crea8s (http://www.crea8s.com) All Rights Reserved.
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp import netsvc

# 
class crea8s_event_registration(osv.osv):
    _inherit = "event.registration"
#     _name = "crea8s.event.registration"
    _description = 'crea8s_event_registration...'
    _columns = {
        'cr_golf_group': fields.many2one('crea8s.golf.group', 'Group', requried=True),
        'cr_golf_ic_number': fields.related('partner_id', 'cr_golf_ic_number', type='char', relation='res.partner', string='IC number'),
        'cr_golf_shirt_size': fields.related('partner_id', 'cr_golf_shirt_size', type='char', relation='res.partner', string='Shirt Size'),
        'cr_golf_qr_code': fields.char(string='QR Code', size=50),

        'cr_golf_score01': fields.float('Hole 01'),
        'cr_golf_score02': fields.float('Hole 02'),
        'cr_golf_score03': fields.float('Hole 03'),
                # Hole for 18holes
        'cr_golf_score04': fields.float('Hole 04'),
        'cr_golf_score05': fields.float('Hole 05'),
        'cr_golf_score06': fields.float('Hole 06'),
        'cr_golf_score07': fields.float('Hole 07'),
        'cr_golf_score08': fields.float('Hole 08'),
        'cr_golf_score09': fields.float('Hole 09'),
        'cr_golf_score10': fields.float('Hole 10'),
        'cr_golf_score11': fields.float('Hole 11'),
        'cr_golf_score12': fields.float('Hole 12'),
        'cr_golf_score13': fields.float('Hole 13'),
        'cr_golf_score14': fields.float('Hole 14'),
        'cr_golf_score15': fields.float('Hole 15'),
        'cr_golf_score16': fields.float('Hole 16'),
        'cr_golf_score17': fields.float('Hole 17'),
        'cr_golf_score18': fields.float('Hole 18'),
        
# 'state': fields.selection([('draft','Draft'),
# ('confirmed','Confirmed')],'State',required=True,readonly=True)
    }
#     strFormatTime = '%Y-%m-%d %H:%M:%S %Z'
    def do_wkf_estimate_sent(self, cr, uid, ids, context={}):
        print "do_wkf_estimate_sent....."
        return True
    
    def onchange_partner_id(self, cr, uid, ids, part, context=None):
        """
            Override onchange function.
            @author: PhongND
            @param part: current partner ID.
        """
        arrSuper = super(crea8s_event_registration, self).onchange_partner_id(cr, uid, ids, part, context) # format: {'value': data}
        
        # get partner info
        ormPartner = self.pool.get('res.partner')
        objPartner = ormPartner.browse(cr, uid, part, context=context)
        if objPartner:
            arrSuper['value'].update({'cr_golf_ic_number': objPartner.cr_golf_ic_number})
            arrSuper['value'].update({'cr_golf_shirt_size': objPartner.cr_golf_shirt_size})
            
            # grant current event_registration for golfer
            if(len(ids) > 0):
                ormPartner.write(cr, uid, [objPartner.id], {'cr_golf_event_regis_current': ids[0]}, context=context)
                
        
        return arrSuper
    
    
    
crea8s_event_registration()




